//
//  OEPrivacyStationViewController.m
//  OneEightyNine
//
//  Created by Mac on 2019/3/5.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEPrivacyStationViewController.h"

@interface OEPrivacyStationViewController ()
@property(nonatomic, strong) NSMutableArray                     *dataSouce;/**< <##> */
@end

@implementation OEPrivacyStationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = OESTRING(@"PRIVACY STATION");
    [self reloadData];
    [self addNotifacations];
    // Do any additional setup after loading the view.
}
#pragma mark --Notifacation
- (void)addNotifacations{
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reloadData)
                                                 name:UIApplicationWillEnterForegroundNotification
                                               object:nil];
    
}

- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)reloadData{
    
    CLAuthorizationStatus status =  [CLLocationManager authorizationStatus];
    NSString * statusSting = @"close";
    if (status == kCLAuthorizationStatusDenied) {
        statusSting = @"open";
    }
    
    PHAuthorizationStatus  photostatus  =  [PHPhotoLibrary authorizationStatus];
    NSString * photoSting = @"close";
    if (photostatus == PHAuthorizationStatusDenied) {
        photoSting = @"open";
    }
    self.dataSouce = NSMutableArray.new;
    ({
         STTableEasyModel * model = [[STTableEasyModel alloc] initWithTextString:@"Opening geographic location" detailString:statusSting];
        model.obj_id = @"Update inventory according to location and recomend accurately";
        [self.dataSouce addObject:model];
    });
    ({
        STTableEasyModel * model = [[STTableEasyModel alloc] initWithTextString:@"Allow access to cameras" detailString:photoSting];
        model.obj_id = @"achieve your scan code,real scene fetch";
        [self.dataSouce addObject:model];
    });
    [self.tableView reloadData];
}

#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return  50;
}
- (NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
    STTableEasyModel * model = self.dataSouce[section];
    return model.obj_id;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.section];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

@end
